
using System;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;

namespace Common
{
    /// <summary>
    /// Description of DiagnoseYGSTTDao.
    /// </summary>
    public class DiagnoseYGSTTDao
    {
        private DiagnoseYGSTTDao()
        {
        }

        public static int insert(DiagnoseYGSTT dy)
        {
            string sql = "insert into DiagnoseYGSTT(diagnose_id,motor_order,motor_frequency,motor_strength,motor_complexity,motor_interference,motor_score,damagerate,severity,phonic_order,phonic_frequency,phonic_strength,phonic_complexity,phonic_interference,phonic_score)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
            OleDbParameter[] parameters = new OleDbParameter[15];
            parameters[0] = new OleDbParameter("@diagnose_id", OleDbType.Integer);
            parameters[0].Value = dy.DiagnoseId;
            parameters[1] = new OleDbParameter("@motor_order", OleDbType.VarChar);
            parameters[1].Value = dy.MotorOrder;
            parameters[2] = new OleDbParameter("@motor_frequency", OleDbType.VarChar);
            parameters[2].Value = dy.MotorFrequency;
            parameters[3] = new OleDbParameter("@motor_strength", OleDbType.VarChar);
            parameters[3].Value = dy.MotorStrength;
            parameters[4] = new OleDbParameter("@motor_complexity", OleDbType.VarChar);
            parameters[4].Value = dy.MotorComplexity;
            parameters[5] = new OleDbParameter("@motor_interference", OleDbType.VarChar);
            parameters[5].Value = dy.MotorInterference;
            parameters[6] = new OleDbParameter("@motor_score", OleDbType.VarChar);
            parameters[6].Value = dy.MotorScore;
            parameters[7] = new OleDbParameter("@damagerate", OleDbType.VarChar);
            parameters[7].Value = dy.DamageRate;
            parameters[8] = new OleDbParameter("@severity", OleDbType.VarChar);
            parameters[8].Value = dy.Severity;
            parameters[9] = new OleDbParameter("@phonic_order", OleDbType.VarChar);
            parameters[9].Value = dy.PhonicOrder;
            parameters[10] = new OleDbParameter("@phonic_frequency", OleDbType.VarChar);
            parameters[10].Value = dy.PhonicFrequency;
            parameters[11] = new OleDbParameter("@phonic_strength", OleDbType.VarChar);
            parameters[11].Value = dy.PhonicStrength;
            parameters[12] = new OleDbParameter("@phonic_complexity", OleDbType.VarChar);
            parameters[12].Value = dy.PhonicComplexity;
            parameters[13] = new OleDbParameter("@phonic_interference", OleDbType.VarChar);
            parameters[13].Value = dy.PhonicInterference;
            parameters[14] = new OleDbParameter("@phonic_score", OleDbType.VarChar);
            parameters[14].Value = dy.PhonicScore;
            return AccessDBUtil.ExecuteInsert(sql, parameters);
        }

        public static int update(DiagnoseYGSTT dy)
        {
            string sql = "update DiagnoseYGSTT set diagnose_id=?,motor_order=?,motor_frequency=?,motor_strength=?,motor_complexity=?,motor_interference=?,motor_score=?,damagerate=?,severity=?,phonic_order=?,phonic_frequency=?,phonic_strength=?,phonic_complexity=?,phonic_interference=?,phonic_score=? where id=?";
            OleDbParameter[] parameters = new OleDbParameter[16];
            parameters[0] = new OleDbParameter("@diagnose_id", OleDbType.Integer);
            parameters[0].Value = dy.DiagnoseId;
            parameters[1] = new OleDbParameter("@motor_order", OleDbType.VarChar);
            parameters[1].Value = dy.MotorOrder;
            parameters[2] = new OleDbParameter("@motor_frequency", OleDbType.VarChar);
            parameters[2].Value = dy.MotorFrequency;
            parameters[3] = new OleDbParameter("@motor_strength", OleDbType.VarChar);
            parameters[3].Value = dy.MotorStrength;
            parameters[4] = new OleDbParameter("@motor_complexity", OleDbType.VarChar);
            parameters[4].Value = dy.MotorComplexity;
            parameters[5] = new OleDbParameter("@motor_interference", OleDbType.VarChar);
            parameters[5].Value = dy.MotorInterference;
            parameters[6] = new OleDbParameter("@motor_score", OleDbType.VarChar);
            parameters[6].Value = dy.MotorScore;
            parameters[7] = new OleDbParameter("@damagerate", OleDbType.VarChar);
            parameters[7].Value = dy.DamageRate;
            parameters[8] = new OleDbParameter("@severity", OleDbType.VarChar);
            parameters[8].Value = dy.Severity;
            parameters[9] = new OleDbParameter("@phonic_order", OleDbType.VarChar);
            parameters[9].Value = dy.PhonicOrder;
            parameters[10] = new OleDbParameter("@phonic_frequency", OleDbType.VarChar);
            parameters[10].Value = dy.PhonicFrequency;
            parameters[11] = new OleDbParameter("@phonic_strength", OleDbType.VarChar);
            parameters[11].Value = dy.PhonicStrength;
            parameters[12] = new OleDbParameter("@phonic_complexity", OleDbType.VarChar);
            parameters[12].Value = dy.PhonicComplexity;
            parameters[13] = new OleDbParameter("@phonic_interference", OleDbType.VarChar);
            parameters[13].Value = dy.PhonicInterference;
            parameters[14] = new OleDbParameter("@phonic_score", OleDbType.VarChar);
            parameters[14].Value = dy.PhonicScore;
            parameters[15] = new OleDbParameter("@id", OleDbType.Integer);
            parameters[15].Value = dy.Id;
            return AccessDBUtil.ExecuteNonQuery(sql, parameters);
        }
        public static DiagnoseYGSTT getById(int id)
        {
            string sql = "select * from DiagnoseYGSTT dy where dy.id=?";
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@id", OleDbType.Integer);
            parameters[0].Value = id;
            DataSet ds = AccessDBUtil.ExecuteQuery(sql, parameters);
            if (ds.Tables["ds"].Rows.Count == 0) return null;
            return Row2DiagnoseYGSTT(ds.Tables["ds"].Rows[0]);
        }

        public static DiagnoseYGSTT getByDiagnoseId(int diagnoseId)
        {
            string sql = "select * from DiagnoseYGSTT dy where dy.diagnose_id=?";
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@diagnose_id", OleDbType.Integer);
            parameters[0].Value = diagnoseId;
            DataSet ds = AccessDBUtil.ExecuteQuery(sql, parameters);
            if (ds.Tables["ds"].Rows.Count == 0) return null;
            return Row2DiagnoseYGSTT(ds.Tables["ds"].Rows[0]);
        }

        public static int deleteById(int id)
        {
            string sql = "delete from DiagnoseYGSTT where id=?";
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@id", OleDbType.Integer);
            parameters[0].Value = id;
            return AccessDBUtil.ExecuteNonQuery(sql, parameters);
        }

        private static DiagnoseYGSTT Row2DiagnoseYGSTT(DataRow row)
        {
            DiagnoseYGSTT dy = new DiagnoseYGSTT();
            dy.Id = Int32.Parse(row["id"].ToString());
            dy.MotorComplexity = row["motor_order"].ToString();
            dy.MotorFrequency = row["motor_frequency"].ToString();
            dy.MotorInterference = row["motor_interference"].ToString();
            dy.MotorOrder = row["motor_order"].ToString();
            dy.MotorScore = row["motor_score"].ToString();
            dy.MotorStrength = row["motor_strength"].ToString();
            dy.PhonicComplexity = row["phonic_order"].ToString();
            dy.PhonicFrequency = row["phonic_frequency"].ToString();
            dy.PhonicInterference = row["phonic_interference"].ToString();
            dy.PhonicOrder = row["phonic_order"].ToString();
            dy.PhonicScore = row["phonic_score"].ToString();
            dy.PhonicStrength = row["phonic_strength"].ToString();
            dy.Severity = row["severity"].ToString();
            dy.DamageRate = row["damagerate"].ToString();
            dy.DiagnoseId = Int32.Parse(row["diagnose_id"].ToString());
            return dy;
        }
    }
}
